/*******************************************************************************
 * This file is part of blueprint4j www.blueprint4j.org.
 * 
 *     blueprint4j is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     blueprint4j is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 * 
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with blueprint4j. If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package blueprint4j.gui.db;

import blueprint4j.db.*;
import blueprint4j.gui.*;
import blueprint4j.utils.*;


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;

/**
 * An entity editor can be placed as a DataPanel inside another entity editor
 * Instead of putting down an entity editor, place a EntityEditorCombiner
 * Your entity editor that is going to be placed inside another should implement
 * EntityEditorCombiner.CombineEntity which will request to build a new instance with
 * a given source bindable
 */
public class EntityEditorCombiner extends DataPanelPlain {
	private CombineEntity ce = null;
	private String name = null;
	private DBConnection connect = null;

	public EntityEditorCombiner(DBConnection connect,CombineEntity ce,String name) {
		this.ce = ce;
		this.name = name;
		this.connect = connect;
	}

	public String getName() {
		return name;
	}

	public void build(Binder binder,Bindable bindable)
	throws IOException, BindException {
		try {
			add(ce.newInstance(connect,binder,bindable));
		} catch (Exception exception) {
			throw new BindException(exception);
		}
	}

	public void activated() {}

	public void deactivated() {}

	public static interface CombineEntity {
		public EntityEditor newInstance(DBConnection connect,Binder binder,Bindable bindable) throws SQLException;
	}

	public EntityEditor getEntityEditor(){return null;}

	public void setEntityEditor(EntityEditor entity_editor) {}
}

